/*
 * @Author: blank
 * @Date: 2024-05-13 14:51:02
 * @Last Modified by: blank
 * @Last Modified time: 2024-05-16 11:28:14
 * 仅用作模拟接口
 */

export function sleep(time = 1000) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(time);
    }, time);
  });
}
function random(...args) {
  if (args.length === 1) {
    return (Math.random() * args[0] ?? 0).toFixed(2);
  }
  if (args.length === 2) {
    return (Math.random() * (args[1] - args[0]) + args[0] ?? 0).toFixed(2);
  }
  return '0.00';
}
/**
 * 获取能源信息
 * @param {{name:string;energyType:string;}[]} list
 * @returns
 */
export async function getEnergyInfo(list) {
  const o = list.map(item => {
    const start = random(500);
    const end = random(500, 1000);
    return {
      ...item,
      value: random(+start, +end),
      /** 同比 */
      yoy: random(-30, 50),
      /** 环比 */
      qoq: random(-10, 30)
    };
  });
  return o;
}

async function test() {
  await sleep(3000);
  console.log('被调用');
}
test();
